package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.NewEnergyStrategy;
import com.ruoyi.mes.service.INewEnergyStrategyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节能策略库Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/mes/energyStrategy")
public class NewEnergyStrategyController extends BaseController
{
    @Autowired
    private INewEnergyStrategyService newEnergyStrategyService;

    /**
     * 查询节能策略库列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyStrategy:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewEnergyStrategy newEnergyStrategy)
    {
        startPage();
        List<NewEnergyStrategy> list = newEnergyStrategyService.selectNewEnergyStrategyList(newEnergyStrategy);
        return getDataTable(list);
    }

    /**
     * 导出节能策略库列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyStrategy:export')")
    @Log(title = "节能策略库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewEnergyStrategy newEnergyStrategy)
    {
        List<NewEnergyStrategy> list = newEnergyStrategyService.selectNewEnergyStrategyList(newEnergyStrategy);
        ExcelUtil<NewEnergyStrategy> util = new ExcelUtil<NewEnergyStrategy>(NewEnergyStrategy.class);
        util.exportExcel(response, list, "节能策略库数据");
    }

    /**
     * 获取节能策略库详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:energyStrategy:query')")
    @GetMapping(value = "/{strategyId}")
    public AjaxResult getInfo(@PathVariable("strategyId") Long strategyId)
    {
        return success(newEnergyStrategyService.selectNewEnergyStrategyByStrategyId(strategyId));
    }

    /**
     * 新增节能策略库
     */
    @PreAuthorize("@ss.hasPermi('mes:energyStrategy:add')")
    @Log(title = "节能策略库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewEnergyStrategy newEnergyStrategy)
    {
        return toAjax(newEnergyStrategyService.insertNewEnergyStrategy(newEnergyStrategy));
    }

    /**
     * 修改节能策略库
     */
    @PreAuthorize("@ss.hasPermi('mes:energyStrategy:edit')")
    @Log(title = "节能策略库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewEnergyStrategy newEnergyStrategy)
    {
        return toAjax(newEnergyStrategyService.updateNewEnergyStrategy(newEnergyStrategy));
    }

    /**
     * 删除节能策略库
     */
    @PreAuthorize("@ss.hasPermi('mes:energyStrategy:remove')")
    @Log(title = "节能策略库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{strategyIds}")
    public AjaxResult remove(@PathVariable Long[] strategyIds)
    {
        return toAjax(newEnergyStrategyService.deleteNewEnergyStrategyByStrategyIds(strategyIds));
    }
}
